package com.ceshi.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ceshi.meta.Product;

public interface ProductDao {
	@Select("select * from content")
	public List<Product> getAllproduct();
	
	@Insert("INSERT INTO content (title,price,text,icon,abstract)VALUES(#{title},#{price},#{text},#{icon},#{summary})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	public void insertProduct(Product product);

	@Select("select id,price,title,icon,abstract,text from content where id=#{id}")
	@Results({  
	    @Result(id=true,property="id",column="id"),  
	    @Result(property="price",column="price"),  
	    @Result(property="title",column="title"),
	    @Result(property="icon",column="icon"),
	    @Result(property="summary",column="abstract"),
	    @Result(property="text",column="text")
	})
	public Product getProductById(int id);

	@Update("update content set title=#{title},price=#{price},text=#{text},icon=#{icon},abstract=#{summary} where id=#{id}")
	public void updateProduct(Product product);
	
	@Delete("delete from content where id=#{id}")
	public void deleteProduct(int id);
}
